
Imports System.Data
Imports System.Data.SqlClient


Namespace Ventas
Public Class ComprobanteDescuento

public Function Listar(ComprobanteDescuentosId as integer) as Entity.Ventas.ComprobanteDescuento

Dim strNameProcedure as string = "up_Ven_ComprobanteDescuento_obtener"
Dim sqlReader As SqlDataReader = Nothing
Dim sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
dim objEnt as   entity.Ventas.ComprobanteDescuento
Try
            sqlCon.Open()
Dim sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
.CommandType = CommandType.StoredProcedure
                .Parameters.Add(New SqlParameter("@ComprobanteDescuentosId", SqlDbType.Int)).Value =ComprobanteDescuentosId
            End With
            sqlReader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
If sqlReader.HasRows Then
While sqlReader.Read
 objEnt= new    entity.Ventas.ComprobanteDescuento
With objEnt
		.ComprobanteDescuentosId = sqlReader("ComprobanteDescuentosId").ToString
		.ComprobanteId = sqlReader("ComprobanteId").ToString
		.DescuentoId = sqlReader("DescuentoId").ToString
		.Tipo = sqlReader("Tipo").ToString
		.Porcentaje = sqlReader("Porcentaje").ToString
		.Monto = sqlReader("Monto").ToString
		.EStado = sqlReader("EStado").ToString
End With
  End While
  End IF
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 sqlReader.Dispose()
  sqlReader.Close()
  sqlReader = Nothing
  sqlCon.Dispose()
 sqlCon.Close()
 sqlCon = Nothing
 End Try
return objEnt

End Function


'***************************



public Function Listar(Opcion as string , _
		ComprobanteDescuentosId as Integer, _
		ComprobanteId as Integer, _
		DescuentoId as Integer, _
		Tipo as Integer, _
		Porcentaje as Double, _
		Monto as Double, _
		EStado as Integer) _
as  Entity.Ventas.ComprobanteDescuentoCol

Dim strNameProcedure as string = "up_Ven_ComprobanteDescuento_listar"
dim objCol as   entity.Ventas.ComprobanteDescuentoCol
Try
Using conn As New SqlConnection(Configuracion.Connexion.Cnn)
Dim cmd As New SqlCommand(strNameProcedure, conn)
cmd.CommandType = CommandType.StoredProcedure
  cmd.Parameters.Add(New SqlParameter("@opcion", SqlDbType.varchar,50)).Value =Opcion
 cmd.Parameters.Add(New SqlParameter("@ComprobanteDescuentosId",SqlDbType.INT)).Value =ComprobanteDescuentosId
 cmd.Parameters.Add(New SqlParameter("@ComprobanteId",SqlDbType.INT)).Value =ComprobanteId
 cmd.Parameters.Add(New SqlParameter("@DescuentoId",SqlDbType.INT)).Value =DescuentoId
 cmd.Parameters.Add(New SqlParameter("@Tipo",SqlDbType.INT)).Value =Tipo
 cmd.Parameters.Add(New SqlParameter("@Porcentaje",SqlDbType.DECIMAL,18)).Value =Porcentaje
 cmd.Parameters.Add(New SqlParameter("@Monto",SqlDbType.DECIMAL,18)).Value =Monto
 cmd.Parameters.Add(New SqlParameter("@EStado",SqlDbType.SMALLINT)).Value =EStado
conn.Open()
Using dr As SqlDataReader = cmd.ExecuteReader()
		dim iComprobanteDescuentosId as integer = dr.GetOrdinal("ComprobanteDescuentosId")
		dim iComprobanteId as integer = dr.GetOrdinal("ComprobanteId")
		dim iDescuentoId as integer = dr.GetOrdinal("DescuentoId")
		dim iTipo as integer = dr.GetOrdinal("Tipo")
		dim iPorcentaje as integer = dr.GetOrdinal("Porcentaje")
		dim iMonto as integer = dr.GetOrdinal("Monto")
		dim iEStado as integer = dr.GetOrdinal("EStado")
		dim i_usu_cre as integer = dr.GetOrdinal("_usu_cre")
		dim i_fec_cre as integer = dr.GetOrdinal("_fec_cre")
		dim i_usu_mod as integer = dr.GetOrdinal("_usu_mod")
		dim i_fec_mod as integer = dr.GetOrdinal("_fec_mod")
		dim i_flg_eli as integer = dr.GetOrdinal("_flg_eli")

 Dim colCount As Integer = dr.FieldCount
 Dim values As Object() = New Object(colCount - 1) {}

 objCol =  New entity.Ventas.ComprobanteDescuentoCol
  If dr.HasRows Then
While dr.Read()
dim objEnt =  new entity.Ventas.ComprobanteDescuento
dr.GetValues(values)

		objEnt.ComprobanteDescuentosId = values(iComprobanteDescuentosId)
		objEnt.ComprobanteId = values(iComprobanteId)
		objEnt.DescuentoId = values(iDescuentoId)
		objEnt.Tipo = values(iTipo)
		objEnt.Porcentaje = values(iPorcentaje)
		objEnt.Monto = values(iMonto)
		objEnt.EStado = values(iEStado)
 objCol.Add(objEnt)
 End While
 End if
 End Using
 End Using
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 End Try
return objCol

End Function


'***************************


Public  Function Insert(ByVal opcion As String, _
		ComprobanteDescuentosId as Integer, _
		ComprobanteId as Integer, _
		DescuentoId as Integer, _
		Tipo as Integer, _
		Porcentaje as Double, _
		Monto as Double, _
		EStado as Integer, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Ven_ComprobanteDescuento_Insertar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@ComprobanteDescuentosId",SqlDbType.INT)).Value =ComprobanteDescuentosId
 .Parameters.Add(New SqlParameter("@ComprobanteId",SqlDbType.INT)).Value =ComprobanteId
 .Parameters.Add(New SqlParameter("@DescuentoId",SqlDbType.INT)).Value =DescuentoId
 .Parameters.Add(New SqlParameter("@Tipo",SqlDbType.INT)).Value =Tipo
 .Parameters.Add(New SqlParameter("@Porcentaje",SqlDbType.DECIMAL,18)).Value =Porcentaje
 .Parameters.Add(New SqlParameter("@Monto",SqlDbType.DECIMAL,18)).Value =Monto
 .Parameters.Add(New SqlParameter("@EStado",SqlDbType.SMALLINT)).Value =EStado
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public  Function Update(ByVal opcion As String, _
		ComprobanteDescuentosId as Integer, _
		ComprobanteId as Integer, _
		DescuentoId as Integer, _
		Tipo as Integer, _
		Porcentaje as Double, _
		Monto as Double, _
		EStado as Integer, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Ven_ComprobanteDescuento_Actualizar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@ComprobanteDescuentosId",SqlDbType.INT)).Value =ComprobanteDescuentosId
 .Parameters.Add(New SqlParameter("@ComprobanteId",SqlDbType.INT)).Value =ComprobanteId
 .Parameters.Add(New SqlParameter("@DescuentoId",SqlDbType.INT)).Value =DescuentoId
 .Parameters.Add(New SqlParameter("@Tipo",SqlDbType.INT)).Value =Tipo
 .Parameters.Add(New SqlParameter("@Porcentaje",SqlDbType.DECIMAL,18)).Value =Porcentaje
 .Parameters.Add(New SqlParameter("@Monto",SqlDbType.DECIMAL,18)).Value =Monto
 .Parameters.Add(New SqlParameter("@EStado",SqlDbType.SMALLINT)).Value =EStado
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public Shared Function Eliminar(ByVal opcion As String, ComprobanteDescuentosId as integer, vusuario as integer) as integer

 dim strNameProcedure as string ="Up_Ven_ComprobanteDescuento_Eliminar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
                .Parameters.Add(New SqlParameter("@ComprobanteDescuentosId", SqlDbType.Int)).Value =ComprobanteDescuentosId
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************



End Class



end namespace

